package com.ujiuye.dao;

import com.ujiuye.entity.Student;
import com.ujiuye.utils.PageUtils;

import java.util.List;

public class StudentDao extends BaseDao<Student> {
    // 查询所有学生信息
    public List<Student> queryStudents() {
        String sql = "select * from stu";
        return queryMore(sql, Student.class);
    }

    //根据id删除学生信息
    public int delStuById(String id) {
        String sql = "delete from stu where sid = ?";
        return update(sql, id);
    }

    //添加学生信息
    public int addStu(Student s) {
        String sql = "insert into stu(sname,age,tel,sbir,sex,spic)values(?,?,?,?,?,?)";
        Object[] params = {s.getSname(), s.getAge(), s.getTel(), s.getSbir(), s.getSex(), s.getSpic()};
        return update(sql, params);
    }

    //根据id查询学生信息
    public Student queryStuById(String id) {
        String sql = "select * from stu where sid = ?";
        return queryOne(sql, Student.class, id);
    }

    //修改学生信息
    public int updateStu(Student s) {
        String sql = "update stu set sname=?,age=?,tel=?,sbir=?,sex=?,spic=? where sid=? ";
        Object[] params = {s.getSname(), s.getAge(), s.getTel(), s.getSbir(), s.getSex(), s.getSpic(), s.getSid()};
        return update(sql, params);
    }

    //分页查询
    public List<Student> queryStuPage(PageUtils pu) {
        String sql = "select * from stu limit ?,?";
        return queryMore(sql, Student.class, pu.getStartIndex(), pu.getPageSize());
    }

    //查询总记录数
    public int queryNum() {
        String sql = "select count(*) from stu";
        return queryScar(sql).intValue();
    }
    //模糊查询

}
